'use strict';

const BaseService = require('./base');

class PostService extends BaseService {
  constructor(ctx) {
    super(ctx, 'Post');
  }

  // 重写getPage方法，增加会员信息
  async getPage(where, page, pageSize) {
    const { app } = this.ctx;
    const include = [{
      model: app.model.Member,
      as: 'member',
      attributes: ['id', 'nickname', 'avatar'],
    }];
    return super.getPage(where, page, pageSize, include);
  }

  // 重写findOne方法，增加会员信息
  async findOne(id) {
    const { app } = this.ctx;
    const include = [{
      model: app.model.Member,
      as: 'member',
      attributes: ['id', 'nickname', 'avatar'],
    }];
    return super.findOne(id, include);
  }
}

module.exports = PostService;
